package com.soft863.tc.analysis;

import com.soft863.tc.analysis.io.MySQLTextOutputFormat;
import com.soft863.tc.analysis.mapper.AnalysisTextMapper;
import com.soft863.tc.analysis.reducer.AnalysisTextReducer;
import com.soft863.tc.common.constant.Names;
import org.apache.hadoop.hbase.client.Scan;
import org.apache.hadoop.hbase.mapreduce.TableMapReduceUtil;
import org.apache.hadoop.hbase.util.Bytes;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;

import java.io.IOException;

public class Driver {
    public static void main(String[] args) throws IOException, ClassNotFoundException, InterruptedException {
        Job job = Job.getInstance();
        job.setJarByClass(Driver.class);

        Scan scan = new Scan();
        scan.addFamily(Bytes.toBytes(Names.CF_CALLER.getValue()));
        //mapper
        TableMapReduceUtil.initTableMapperJob(
                Names.TABLE.getValue(),
                scan,
                AnalysisTextMapper.class,
                Text.class,
                Text.class,
                job
        );

        //reducer
        job.setReducerClass(AnalysisTextReducer.class);
        job.setOutputKeyClass(Text.class);
        job.setOutputValueClass(Text.class);

        //outPutFormat
        job.setOutputFormatClass(MySQLTextOutputFormat.class);
        job.waitForCompletion(true);
    }
}
